import {
  getBatchPlanByPage,
  countUnAssginProduct,
  getBatchPlanAndStageByPage,
  updateBatchPlanStageTime,
  getBatchPlanAndStageByPageAndInfoId,
  addBatchPlan,
  updateBatchPlan,
  delBatchPlan,
  updateBatchPlanTime,
  genAddBatchPlanForm,
  genUpdateBatchPlanForm,
  updateBatchPlanProduct,
  releaseBatchPlan,
} from '@/services/project/batchPlan';
import { history } from 'umi';
import {
  ModalForm,
  ProForm,
  ProFormDatePicker,
  ProFormTextArea,
  ProFormText,
} from '@ant-design/pro-components';
import { PlusOutlined, ArrowLeftOutlined, RiseOutlined } from '@ant-design/icons';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { Button, Form, message, Modal, Table } from 'antd';
import { sortTran, filterTran, filterTranNew } from '@/utils/requestUtil';
import React, { useRef, useState } from 'react';
import type { ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import { Ellipsis } from '@/components/Ellipsis';

const BatchPlan = React.forwardRef((props, ref) => {
  const actionRef = useRef<ActionType>();
  const [modalVisit, setModalVisit] = useState(false); // 新建和编辑提示框
  const [confirmLoading, setConfirmLoading] = useState(false); //编辑框的disable
  const [formTitle, setFormTitle] = useState('新建'); //
  const [form] = Form.useForm();
  const [beginFormInfo, setBeginFormInfo] = useState({});
  const [editFormInfo, setEditFormInfo] = useState([]);
  const [tableInfo, setTableInfo] = useState([]);
  const [editTableInfo, setEditTableInfo] = useState([]);
  const [formRef] = Form.useForm();
  const [timeRef] = Form.useForm();
  const [editFormRef] = Form.useForm();
  const [selectKeys, setSelectKeys] = useState([]);
  const [batchPlanId, setbatchPlanId] = useState(null);
  const refs = useRef(null);
  const [selections, setSelections] = useState([]);
  const [hiddenTemp, setHiddenTemp] = useState(false);
  const [selectedRowKey, setSelectedRowKey] = useState([]);
  const [selectedRowKey2, setSelectedRowKeys2] = useState([]);
  const [selectionType, setSelectionType] = useState<'checkbox' | 'radio'>('checkbox');
  const [tempDate, setTempDate] = useState<any[]>();
  const [recordState, setRecordState] = useState<boolean>(true);
  const [batchCount, setBatchCount] = useState<number>(-1);
  const [releaseBtnFlag, setreleaseBtnFlag] = useState<boolean>(false);
  const stateType = ['未下发', '已下发', '已下发', '暂停'];
  const [tableData, setTableData] = useState([]); //用于存储所有的批次计划，方便发布时全选
  const [infoId, setInfoId] = useState(); //用于判断该页面打开的位置
  const [resultLength, setResultLength] = useState(0);

  const [thenumber, setthenumber] = useState(); //记录选中的柜体总数量
  const [theproductid, settheproductid] = useState([]); //编辑批次时保留选中的id
  const batchPlanFlag = props.batchPlanFlag;
  const batchPlanInfoId = props.batchPlanInfoId;

  React.useImperativeHandle(ref, () => ({
    update() {
      actionRef.current?.reload();
    },
  }));
  //编辑时间
  const editTime = async (params: any) => {
    const result = await updateBatchPlanTime(params);
    if (result != null) {
      message.success('修改成功！');
    }
    actionRef.current!.reload();
  };

  //日期联动
  const listenDate = (dateString: Date, date: string) => {
    if (!(dateString == null)) {
      timeRef.setFieldsValue({
        [date]: dayjs(dateString).add(1, 'day').format('YYYY-MM-DD'),
      });
    }
  };

  //开始日期与前一项结束日期联动
  const DateModify = (value: any, date: string) => {
    if (value) {
      timeRef.setFieldsValue({
        [date]: dayjs(value).subtract(1, 'day').format('YYYY-MM-DD'),
      });
    }
  };

  //发布柜体信息
  const releaseProduct = async () => {
    if (selectedRowKey.length !== 0) {
      const result = await releaseBatchPlan(selectedRowKey);
      if (result != null) {
        message.success('发布成功');
      }
      setreleaseBtnFlag(false);
      setSelectedRowKey([]);
      actionRef.current?.reload();
    } else {
      message.info('请先选中您要发布的批次信息!');
    }
  };

  //单选
  const onSelectItem = (record: any, selected: any, selectedRows: any[]) => {
    const temp: string[] = [];
    if (selectedRows !== null) {
      selectedRows.map((item) => {
        if (item !== null) {
          temp.push(item.id);
        }
      });
    }
    console.log(temp, '被选中的内容');
    setSelectedRowKey(temp);
    setthenumber(
      record.cabinetCount + record.boxCount + record.operationCount + record.othersCount,
    );
  };

  //全选
  const onSelectedAllItem = (selected: any, selectedRows: any, changeRows: any) => {
    if (selected) {
      //如果全被选
      const temp: string[] = [];
      if (tableData !== null) {
        tableData.map((item) => {
          if (item !== null) {
            temp.push(item.batchPlanEx.id);
          }
        });
      }
      console.log(temp, '全选的内容');
      setSelectedRowKey(temp);
    } else {
      console.log('empty');
      setSelectedRowKey([]);
    }
  };

  const columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',

      width: 80,
    },

    {
      title: '项目名称',
      dataIndex: 'projectName',
      // valueType: 'select',      sorter:true,
      width: 200,
      align: 'center',
      sorter: true,
      // fieldProps: {
      //   options: ,
      // },
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划编号',
      dataIndex: 'batchPlanCode',

      width: 200,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '状态',
      dataIndex: 'state',
      width: 60,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <div>{text === -1 ? '暂停' : stateType[text]}</div>,
    },
    {
      title: '项目交付日期',
      dataIndex: 'infoDeliveryDate',
      width: 120,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      search: false,
    },
    {
      title: '项目交付日期',
      dataIndex: 'infoDeliveryDate',
      valueType: 'dateRange',
      hideInTable: true,
    },
    {
      title: 'C',
      dataIndex: 'cabinetCount',

      width: 50,
      align: 'center',
      sorter: true,
      search: false,
    },
    {
      title: 'B',
      dataIndex: 'boxCount',
      width: 50,
      search: false,

      align: 'center',
      sorter: true,
    },
    {
      title: 'P',
      dataIndex: 'operationCount',
      width: 50,

      search: false,
      align: 'center',
      sorter: true,
    },
    {
      title: 'others',
      dataIndex: 'othersCount',
      width: 70,
      search: false,

      align: 'center',
      sorter: true,
    },
    {
      title: '当前批次',
      dataIndex: 'currentBatch',
      width: 90,
      search: false,
      align: 'center',
      sorter: true,
      render: (text, record) => (
        <div>
          {text}/{record.batchCount}
        </div>
      ),
    },
    {
      title: `批次交付日期`,
      dataIndex: 'stagePlanEndTime7',
      valueType: 'date',
      width: 130,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
/*     {
      title: '数量齐套率/%',
      dataIndex: 'numPercent',
      width: 120,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      // render: (text, record, _, action) => {
      //   return <div>100</div>;
      // },
    },
    {
      title: '种类齐套率/%',
      dataIndex: 'typePercent',
      width: 120,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      // render: (text, record, _, action) => {
      //   return <div>100</div>;
      // },
    }, */
    {
      title: '实际工时',
      dataIndex: 'realWorkHour',
      width: 100,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => {
        return text === '-' ? Number(0).toFixed(2) : Number(text).toFixed(2);
      },
      //
    },
    {
      title: '计划工时',
      width: 100,
      align: 'center',
      sorter: true,
      search: false,
      dataIndex: 'workHour',
      render: (text) => {
        return text === '-' ? Number(0).toFixed(2) : Number(text).toFixed(2);
      },
      //
    },

    // {
    //   title: '批次总数',
    //   dataIndex: 'batchCount',
    //   width: 90,
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: '标准工时',
    //   dataIndex: 'realWorkHour',

    //   width: 90,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => {
    //     return text === '-' ? Number(0).toFixed(2) + 'h' : Number(text).toFixed(2) + 'h';
    //   },
    // },
    // {
    //   title: '实际工时',
    //   dataIndex: 'workHour',

    //   width: 90,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => {
    //     return text === '-' ? Number(0).toFixed(2) + 'h' : Number(text).toFixed(2) + 'h';
    //   },
    // },
    {
      title: `项目开工计划开始`,
      dataIndex: 'stagePlanStartTime1',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `项目开工计划结束`,
      dataIndex: 'stagePlanEndTime1',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },

    {
      title: `项目开工实际开始`,
      dataIndex: 'stageStartTime1',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `项目开工实际结束`,
      dataIndex: 'stageEndTime1',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `柜体设计计划开始`,
      dataIndex: 'stagePlanStartTime2',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `柜体设计计划结束`,
      dataIndex: 'stagePlanEndTime2',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `柜体设计实际开始`,
      dataIndex: 'stageStartTime2',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `柜体设计实际结束`,
      dataIndex: 'stageEndTime2',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `物料采购计划开始`,
      dataIndex: 'stagePlanStartTime3',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `物料采购计划结束`,
      dataIndex: 'stagePlanEndTime3',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `物料采购实际开始`,
      dataIndex: 'stageStartTime3',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `物料采购实际结束`,
      dataIndex: 'stageEndTime3',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产分料计划开始`,
      dataIndex: 'stagePlanStartTime4',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产分料计划结束`,
      dataIndex: 'stagePlanEndTime4',
      valueType: 'date',
      search: false,
      width: 80,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产分料实际开始`,
      dataIndex: 'stageStartTime4',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产分料实际结束`,
      dataIndex: 'stageEndTime4',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产装配计划开始`,
      dataIndex: 'stagePlanStartTime5',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产装配计划结束`,
      dataIndex: 'stagePlanEndTime5',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产装配实际开始`,
      dataIndex: 'stageStartTime5',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `生产装配实际结束`,
      dataIndex: 'stageEndTime5',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `打包入库计划开始`,
      dataIndex: 'stagePlanStartTime6',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `打包入库计划结束`,
      dataIndex: 'stagePlanEndTime6',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `打包入库实际开始`,
      dataIndex: 'stageStartTime6',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `打包入库实际结束`,
      dataIndex: 'stageEndTime6',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `发货日期计划结束`,
      dataIndex: 'stagePlanEndTime7',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `发货日期实际开始`,
      dataIndex: 'stageStartTime7',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: `发货日期实际结束`,
      dataIndex: 'stageEndTime7',
      valueType: 'date',
      width: 80,
      search: false,
      align: 'center',
      sorter: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    // {
    //   title: `现场安装计划开始`,
    //   dataIndex: 'stagePlanStartTime8',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场安装计划结束`,
    //   dataIndex: 'stagePlanEndTime8',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场安装实际开始`,
    //   dataIndex: 'stageStartTime8',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场安装实际结束`,
    //   dataIndex: 'stageEndTime8',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场调试计划开始`,
    //   dataIndex: 'stagePlanStartTime9',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场调试计划结束`,
    //   dataIndex: 'stagePlanEndTime9',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场调试实际开始`,
    //   dataIndex: 'stageStartTime9',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `现场调试实际结束`,
    //   dataIndex: 'stageEndTime9',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `项目验收计划开始`,
    //   width: 80,
    //   dataIndex: 'stagePlanStartTime10',
    //   valueType: 'date',
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `项目验收计划结束`,
    //   dataIndex: 'stagePlanEndTime10',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `项目验收实际开始`,
    //   dataIndex: 'stageStartTime10',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: `项目验收实际结束`,
    //   dataIndex: 'stageEndTime10',
    //   valueType: 'date',
    //   width: 80,
    //   search: false,
    //   align: 'center',
    //   sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: '备注',
    //   dataIndex: 'memo',
    //   width: 90,
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: '预留',
    //   dataIndex: 'reserved',
    //   width: 90,
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    // {
    //   title: '流水号',
    //   dataIndex: 'serialNo',
    //   width: 90,
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    {
      title: '创建日期', //表头显示的名称
      search: false,
      dataIndex: 'createTime',
      valueType: 'date',
      width: 100,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '创建人', //表头显示的名称
      search: false,
      dataIndex: 'createName',
      width: 90,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      align: 'center',
      width: 200,
      render: (text, record, _, action) => [
        <a
          key="editKey"
          onClick={() => {
            setFormTitle('编辑');
          }}
        >
          <ModalForm
            key="add"
            title="计划"
            trigger={
              <span
                onClick={() => {
                  timeRef.setFieldsValue({
                    stageStartTime1: record.stageStartTime1,
                    stageStartTime2: record.stageStartTime2,
                    stageStartTime3: record.stageStartTime3,
                    stageStartTime4: record.stageStartTime4,
                    stageStartTime5: record.stageStartTime5,
                    stageStartTime6: record.stageStartTime6,
                    stageStartTime7: record.stageStartTime7,
                    stageStartTime8: record.stageStartTime8,
                    stageStartTime9: record.stageStartTime9,
                    stageStartTime10: record.stageStartTime10,
                    stageEndTime1: record.stageEndTime1,
                    stageEndTime2: record.stageEndTime2,
                    stageEndTime3: record.stageEndTime3,
                    stageEndTime4: record.stageEndTime4,
                    stageEndTime5: record.stageEndTime5,
                    stageEndTime6: record.stageEndTime6,
                    stageEndTime7: record.stageEndTime7,
                    stageEndTime8: record.stageEndTime8,
                    stageEndTime9: record.stageEndTime9,
                    stageEndTime10: record.stageEndTime10,
                    stagePlanStartTime1: record.stagePlanStartTime1,
                    stagePlanStartTime2: record.stagePlanStartTime2,
                    stagePlanStartTime3: record.stagePlanStartTime3,
                    stagePlanStartTime4: record.stagePlanStartTime4,
                    stagePlanStartTime5: record.stagePlanStartTime5,
                    stagePlanStartTime6: record.stagePlanStartTime6,
                    stagePlanStartTime7: record.stagePlanStartTime7,
                    // stagePlanStartTime8: record.stagePlanStartTime8,
                    // stagePlanStartTime9: record.stagePlanStartTime9,
                    // stagePlanStartTime10: record.stagePlanStartTime10,
                    stagePlanEndTime1: record.stagePlanEndTime1,
                    stagePlanEndTime2: record.stagePlanEndTime2,
                    stagePlanEndTime3: record.stagePlanEndTime3,
                    stagePlanEndTime4: record.stagePlanEndTime4,
                    stagePlanEndTime5: record.stagePlanEndTime5,
                    stagePlanEndTime6: record.stagePlanEndTime6,
                    stagePlanEndTime7: record.stagePlanEndTime7,
                    stagePlanEndTime8: record.stagePlanEndTime8,
                    stagePlanEndTime9: record.stagePlanEndTime9,
                    stagePlanEndTime10: record.stagePlanEndTime10,
                  });
                }}
              >
                计划
              </span>
            }
            form={timeRef}
            width={900}
            modalProps={{
              onCancel: () => {
                timeRef.setFieldsValue({
                  stageStartTime1: record.stageStartTime1,
                  stageStartTime2: record.stageStartTime2,
                  stageStartTime3: record.stageStartTime3,
                  stageStartTime4: record.stageStartTime4,
                  stageStartTime5: record.stageStartTime5,
                  stageStartTime6: record.stageStartTime6,
                  stageStartTime7: record.stageStartTime7,
                  // stageStartTime8: record.stageStartTime8,
                  // stageStartTime9: record.stageStartTime9,
                  // stageStartTime10: record.stageStartTime10,
                  stageEndTime1: record.stageEndTime1,
                  stageEndTime2: record.stageEndTime2,
                  stageEndTime3: record.stageEndTime3,
                  stageEndTime4: record.stageEndTime4,
                  stageEndTime5: record.stageEndTime5,
                  stageEndTime6: record.stageEndTime6,
                  stageEndTime7: record.stageEndTime7,
                  // stageEndTime8: record.stageEndTime8,
                  // stageEndTime9: record.stageEndTime9,
                  // stageEndTime10: record.stageEndTime10,
                  stagePlanStartTime1: record.stagePlanStartTime1,
                  stagePlanStartTime2: record.stagePlanStartTime2,
                  stagePlanStartTime3: record.stagePlanStartTime3,
                  stagePlanStartTime4: record.stagePlanStartTime4,
                  stagePlanStartTime5: record.stagePlanStartTime5,
                  stagePlanStartTime6: record.stagePlanStartTime6,
                  stagePlanStartTime7: record.stagePlanStartTime7,
                  // stagePlanStartTime8: record.stagePlanStartTime8,
                  // stagePlanStartTime9: record.stagePlanStartTime9,
                  // stagePlanStartTime10: record.stagePlanStartTime10,
                  stagePlanEndTime1: record.stagePlanEndTime1,
                  stagePlanEndTime2: record.stagePlanEndTime2,
                  stagePlanEndTime3: record.stagePlanEndTime3,
                  stagePlanEndTime4: record.stagePlanEndTime4,
                  stagePlanEndTime5: record.stagePlanEndTime5,
                  stagePlanEndTime6: record.stagePlanEndTime6,
                  stagePlanEndTime7: record.stagePlanEndTime7,
                  // stagePlanEndTime8: record.stagePlanEndTime8,
                  // stagePlanEndTime9: record.stagePlanEndTime9,
                  // stagePlanEndTime10: record.stagePlanEndTime10,
                  reserved: record.reserved,
                  serialNo: record.serialNo,
                  masterPlanId: record.masterPlanId,
                  currentBatch: record.currentBatch,
                  batchCount: record.batchCount,
                  realWorkHour: record.realWorkHour,
                  workHour: record.workHour,
                  infoId: record.infoId,
                  projectName: record.projectName,
                  batchDeliveryDate: record.batchDeliveryDate,
                  id: record.id,
                });
              },
              footer: null,
              destroyOnClose: true,
            }}
            onFinish={async (values: any) => {
              const res = timeRef.getFieldsValue();
              //构造参数
              let temp = [];
              for (let i = 1; i <= 7; i++) {
                temp.push({
                  id: record && `${record['id' + i]}`,
                  stagePlanEndTime:
                    res &&
                    res['stagePlanEndTime' + i] &&
                    dayjs(`${res['stagePlanEndTime' + i]}`).format('YYYY-MM-DD'),
                  stagePlanStartTime:
                    res &&
                    res['stagePlanStartTime' + i] &&
                    dayjs(`${res['stagePlanStartTime' + i]}`).format('YYYY-MM-DD'),
                  stageStartTime:
                    res &&
                    res['stageStartTime' + i] &&
                    dayjs(`${res['stageStartTime' + i]}`).format('YYYY-MM-DD'),
                  stageEndTime:
                    res &&
                    res['stageEndTime' + i] &&
                    dayjs(`${res['stageEndTime' + i]}`).format('YYYY-MM-DD'),
                });
              }
              const result = await updateBatchPlanStageTime(temp);
              if (result && result.code === 0) {
                message.success('更新成功');
                actionRef.current!.reload();
                return true;
              }
            }}
          >
            <ProForm.Group>
              <div style={{ marginTop: 30 }}>
                {tempDate && tempDate[0] && tempDate[0].stageName1}
              </div>
              <ProFormDatePicker name="stagePlanStartTime1" label="计划开始日期" />
              <ProFormDatePicker
                name="stagePlanEndTime1"
                label="计划结束日期"
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime2');
                }}
              />
              <ProFormDatePicker name="stageStartTime1" label="实际开始日期" disabled />
              <ProFormDatePicker name="stageEndTime1" label="实际结束日期" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName2}</div>
              <ProFormDatePicker
                name="stagePlanStartTime2"
                label=""
                onChange={(date: any) => {
                  DateModify(date, 'stagePlanEndTime1');
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime2"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime3');
                }}
              />
              <ProFormDatePicker name="stageStartTime2" label="" disabled />
              <ProFormDatePicker name="stageEndTime2" label="" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName3}</div>
              <ProFormDatePicker
                name="stagePlanStartTime3"
                label=""
                onChange={(date: any) => {
                  DateModify(date, 'stagePlanEndTime2');
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime3"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime4');
                }}
              />
              <ProFormDatePicker name="stageStartTime3" label="" disabled />
              <ProFormDatePicker name="stageEndTime3" label="" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName4}</div>
              <ProFormDatePicker
                name="stagePlanStartTime4"
                label=""
                onChange={(date: any) => {
                  DateModify(date, 'stagePlanEndTime3');
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime4"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime5');
                }}
              />
              <ProFormDatePicker name="stageStartTime4" label="" disabled />
              <ProFormDatePicker name="stageEndTime4" label="" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName5}</div>
              <ProFormDatePicker
                name="stagePlanStartTime5"
                label=""
                onChange={(date: any) => {
                  DateModify(date, 'stagePlanEndTime4');
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime5"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime6');
                }}
              />
              <ProFormDatePicker name="stageStartTime5" label="" disabled />
              <ProFormDatePicker name="stageEndTime5" label="" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName6}</div>
              <ProFormDatePicker
                name="stagePlanStartTime6"
                label=""
                onChange={(date: any) => {
                  DateModify(date, 'stagePlanEndTime5');
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime6"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime7');
                }}
              />
              <ProFormDatePicker name="stageStartTime6" label="" disabled />
              <ProFormDatePicker name="stageEndTime6" label="" disabled />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName7}</div>
              <ProFormDatePicker
                name="stagePlanStartTime7"
                label=""
                onChange={(date: string | number | Date | dayjs.Dayjs | null | undefined) => {
                  //两个日期比较大小
                  const date1Target = timeRef.getFieldValue('stagePlanEndTime6');
                  if (dayjs(date1Target).isAfter(dayjs(date))) {
                    //表格数据校验出错
                    timeRef.setFields([
                      {
                        name: 'stagePlanStartTime7',
                        errors: ['发货需晚于打包入库'],
                      },
                    ]);
                  } else {
                    DateModify(date, 'stagePlanEndTime6');
                  }
                }}
              />
              <ProFormDatePicker
                name="stagePlanEndTime7"
                label=""
                disabled
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime8');
                }}
              />
              <ProFormDatePicker name="stageStartTime7" label="" />
              <ProFormDatePicker name="stageEndTime7" label="" />
            </ProForm.Group>
            {/* <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName8}</div> */}
            {/* <ProFormDatePicker name="stagePlanStartTime8" label="" />
              <ProFormDatePicker
                name="stagePlanEndTime8"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime9');
                }}
              />
              <ProFormDatePicker name="stageStartTime8" label="" />
              <ProFormDatePicker name="stageEndTime8" label="" />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName9} </div>
              <ProFormDatePicker name="stagePlanStartTime9" label="" />
              <ProFormDatePicker
                name="stagePlanEndTime9"
                label=""
                onChange={(date: Date) => {
                  listenDate(date, 'stagePlanStartTime10');
                }}
              />
              <ProFormDatePicker name="stageStartTime9" label="" />
              <ProFormDatePicker name="stageEndTime9" label="" />
            </ProForm.Group>
            <ProForm.Group>
              <div style={{}}>{tempDate && tempDate[0] && tempDate[0].stageName10}</div>
              <ProFormDatePicker name="stagePlanStartTime10" label="" />
              <ProFormDatePicker name="stagePlanEndTime10" label="" />
              <ProFormDatePicker name="stageStartTime10" label="" />
              <ProFormDatePicker name="stageEndTime10" label="" />
            </ProForm.Group> */}
          </ModalForm>
        </a>,
        <a key="edKey">
          <ModalForm
            key="eidtBatch"
            title="批次"
            modalProps={{
              destroyOnClose: true,
              onCancel: () => {
                setSelections([]);
                actionRef.current?.clearSelected();
              },
            }}
            width={1500}
            request={async () => {
              const result = await genUpdateBatchPlanForm(record.id);
              // console.log(genUpdateBatchPlanForm,'result.data');
              setEditTableInfo(result.data);
              editFormRef.setFieldsValue({
                infoDeliveryDate: result.data.infoDeliveryDate,
                batchDeliveryDate: result.data.batchDeliveryDate,
                //batchCount: editTableInfo.batchCount,
                memo: result.data.memo,
                currentBatch: result.data.currentBatch + '/' + result.data.batchCount,
              });
              settheproductid(result.data.selectedproductId);
              if (result.data.batchProductSimps !== null) {
                result.data.batchProductSimps.map((item: any, index: number) => {
                  // if (item.isStandard == 1|| item.isStandard == '1') {
                  //   item.isStandard = '是';
                  // } else {
                  //   item.isStandard = '否';
                  // }
                  item.key = index + 1;
                });
                setTableInfo(result.data.batchProductSimps);
              }
              setEditFormInfo(result.data.batchProductSimps);

              //默认选中的序号
              //setSelectKeys(result.data.selectedproductId);
              const tempKeys: Number[] = [];
              const temp: any[] = [];
              result.data.selectedproductId.map((item: any) => {
                tempKeys.push(
                  result.data.batchProductSimps.find(
                    (tempItem: any) => tempItem.batchProductId === item,
                  ).key,
                );
                temp.push(
                  result.data.batchProductSimps.find(
                    (tempItem: any) => tempItem.batchProductId === item,
                  ),
                );
              });
              let tempData: any[] = [];
              if (recordState) {
                tempData = temp;
              } else {
                tempData = result.data;
              }
              setEditFormInfo(
                tempData && tempData.batchProductSimps ? tempData.batchProductSimps : tempData,
              );
              setSelectKeys(tempKeys);
              return {
                data: result.data,
                total: result.data,
                success: result.success,
              };
            }}
            trigger={
              <Button
                style={{ border: 0, backgroundColor: 'transparent', color: '#13c2c2' }}
                onClick={() => {
                  if (record.state == 0) {
                    setRecordState(false);
                  } else {
                    setRecordState(true);
                  }
                }}
              >
                {record.state == 0 ? '批次' : <span>查看</span>}
              </Button>
            }
            form={editFormRef}
            onFinish={async (values: any) => {
              // if (!recordState) {
              // console.log(theproductid,'theproductid');
              // console.log(selections,'selections');
              // 批次和查看，都调用修改接口
              const temp = {
                ...editFormRef.getFieldsValue(),
                infoDeliveryDate: editTableInfo.infoDeliveryDate, //项目交付日期
                masterPlanId: editTableInfo.masterPlanId,
                currentBatch: editTableInfo.currentBatch,
                batchPlanId: editTableInfo?.batchPlanId,
                // selectedBatchProductId: selections,
                selectedBatchProductId: selections.length == 0 ? theproductid : selections,
              };
              temp.batchDeliveryDate = dayjs(temp.batchDeliveryDate).format('YYYY-MM-DD');
              // console.log(temp,'temp');
              const result = await updateBatchPlanProduct(temp);
              if (result != null) {
                message.success('编辑成功');
              }
              // }
              actionRef.current?.clearSelected();
              setSelections([]);
              setRecordState(false);
              actionRef.current!.reload();
              return true;
            }}
          >
            <ProForm.Group>
              <ProFormDatePicker
                rules={[{ required: true, message: '请输入终止日期！' }]}
                name="infoDeliveryDate"
                label="项目交付日期"
                disabled /* ={recordState} */
              />
              <ProFormText name="currentBatch" label="当前批次" placeholder="请输入名称" disabled />
              <ProFormDatePicker
                rules={[{ required: true, message: '请输入批次交付日期！' }]}
                name="batchDeliveryDate"
                label="批次交付日期"
                // disabled={recordState}
              />
            </ProForm.Group>
            <ProForm.Group>
              <Table
                rowSelection={{
                  type: selectionType,
                  ...editRowSelection,
                }}
                // rowSelection={{
                //   ...rowSelection,
                //   selectedRowKeys: selections,
                // }}
                columns={col}
                disabled={recordState}
                scroll={{ x: 650, y: 300 }}
                dataSource={editFormInfo}
                pagination={{ pageSize: 1000 }}
              />
            </ProForm.Group>
            <ProFormTextArea
              name="memo"
              label="描述"
              placeholder="请输入描述"
              disabled={recordState}
              //fieldProps={inputTextAreaProps}
              width={1450}
            />
          </ModalForm>
        </a>,
        <a
          key="deleteKey"
          disabled={resultLength === 1}
          onClick={() => {
            console.log(resultLength);
            if (resultLength === 1) {
              message.warning('批次计划数量为1时不允许删除！');
            } else {
              Modal.confirm({
                title: '删除',
                content: '确定要删除吗',
                okText: '确认',
                cancelText: '取消',
                onOk: async () => {
                  const result = await delBatchPlan({ id: record.id });
                  if (result !== null) {
                    message.success('删除成功');
                  }
                  actionRef.current!.reload();
                },
              });
            }
          }}
        >
          删除
        </a>,
      ],
    },
  ];
  const col: ColumnsType<DataType> = [
    {
      title: '序号',
      key: 'key',
      dataIndex: 'key',
      width: 80,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '柜体编号',
      key: 'productCode',
      dataIndex: 'productCode',
      width: 200,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      sorter: (a, b) => a.productCode.localeCompare(b.productCode),
    },
    {
      title: '柜体描述',
      dataIndex: 'productDesc',
      width: 100,
      align: 'center',
      sorter: true,

      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '柜体类型',
      key: 'productType',
      dataIndex: 'productType',
      width: 100,
      filters: [
        {
          text: '柜体',
          value: '柜体',
        },
        {
          text: '箱体',
          value: '箱体',
        },
        {
          text: '其它',
          value: '其它',
        },
        {
          text: '安装板',
          value: '安装板',
        },
      ],
      onFilter: (value: string, record) => record.productType.indexOf(value) === 0,
      align: 'center',
      sorter: true,
      ellipsis: true,
    },
    {
      title: '标准柜体',
      key: 'isStandard',
      dataIndex: 'isStandard',
      width: 140,
      filters: [
        {
          text: '是',
          value: 1,
        },
        {
          text: '否',
          value: 0,
        },
      ],
      onFilter: (value: number, record) => record.isStandard === value,
      align: 'center',
      sorter: true,
      render: (text) => {
        return <div>{text === 1 ? '是' : '否'}</div>;
      },
    },
  ];
  const rowSelection = {
    onSelect: (record: any, selected: any, selectedRows: any[] | null, nativeEvent: any) => {
      const temp: string[] = [];
      if (selectedRows !== null) {
        selectedRows.map((item) => {
          temp.push(item.batchProductId);
        });
      }
      console.log(temp, '选中内容');
      setSelections(temp);
    },
    //添加批次的全选
    onSelectAll: (selected: any, selectedRows: any, changeRows: any) => {
      if (selected) {
        //如果全被选
        const temp: string[] = [];
        if (tableInfo !== null) {
          tableInfo.map((item) => {
            if (item !== null) {
              temp.push(item.batchProductId);
            }
          });
        }
        console.log(temp, '全选的内容');
        setSelections(temp);
      } else {
        console.log('empty');
        setSelections([]);
      }
    },
  };

  const editRowSelection = {
    onSelect: (record: any, selected: any, selectedRows: any[] | null, nativeEvent: any) => {
      const temp: string[] = [];
      if (selectedRows !== null) {
        selectedRows.map((item) => {
          temp.push(item.batchProductId);
        });
      }
      console.log(temp, '选中内容1');
      setSelections(temp);
    },
    onChange: (selectedRowKeys: React.Key[], selectedRows: DataType[]) => {
      const temp: string[] = [];
      if (selectedRows !== null) {
        selectedRows.map((item) => {
          temp.push(item.batchProductId);
        });
      }
      console.log(temp, '选中内容2');
      setSelections(temp);
    },
    defaultSelectedRowKeys: () => {
      return selectKeys;
    },
  };

  const defaultSelectedRowKeys = () => {
    return ['0'];
  };

  interface DataType {
    key: React.Key;
    productType: string;
    productDesc: string;
    isStandard: number;
    unstandardName: string;
    productQty: number;
    batchProductId: string;
  }

  const handleSubmit = async () => {
    setConfirmLoading(true);
    if (formTitle == '新建') {
    } else {
      await updateBatchPlan(form.getFieldsValue());
    }
    setConfirmLoading(false);
    setModalVisit(false);
    actionRef.current?.reload();
  };

  //生成添加批次计划的表单项
  const getPlanInfo = async () => {
    let result;
    console.log(batchPlanInfoId);
    if (batchPlanFlag !== undefined && !batchPlanFlag) {
      result = await genAddBatchPlanForm(batchPlanInfoId);
    } else {
      result = await genAddBatchPlanForm(history.location.state.infoId);
    }
    if (result.data !== null) {
      setHiddenTemp(false);
      setBeginFormInfo(result.data);
      console.log(result.data, '添加批次');
      if (result.data.batchProductSimps !== null) {
        result.data.batchProductSimps.map((item: any, index: number) => {
          item.key = index + 1;
        });
        setTableInfo(result.data.batchProductSimps);
        formRef.resetFields();
      }
    } else {
      setHiddenTemp(true);
      setTableInfo(null);
    }
  };

  //生成批次计划的表单项
  const editPlanInfo = async () => {
    const result = await genUpdateBatchPlanForm(batchPlanId);

    // if (result.data !== null) {
    //   setEditFormInfo(result.data);
    //   if (result.data.batchProductSimps !== null) {
    //     result.data.batchProductSimps.map((item: any, index: number) => {
    //       item.key = index;
    //     });
    //     setEditTableInfo(result.data.batchProductSimps);
    //     formRef.resetFields();
    //   }
    // } else {
    //   setHiddenTemp(true);
    //   setTableInfo(null);
    // }
  };

  return (
    <PageHeaderWrapper title={false} breadcrumb={undefined}>
      <ProTable
        headerTitle="批次总览查询"
        actionRef={actionRef} //用于触发刷新操作等，看api
        rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
        formRef={refs}
        tableAlertOptionRender={() => {
          return (
            <a
              onClick={() => {
                setSelectedRowKey([]);
                actionRef.current?.clearSelected();
              }}
            >
              取消选择
            </a>
          );
        }} //重写批量选择时右上角的取消选择
        search={{
          ...batchPlanFlag,
          labelWidth: 100,
        }}
        toolBarRender={(action, { selectedRows }) => [
          batchCount !== -1 && (
            <span style={{ float: 'left', fontWeight: 700 }}>
              剩余未分柜体数量信息<span style={{ color: 'red', padding: '5px' }}>{batchCount}</span>
            </span>
          ),
          <Button
            key="button"
            icon={<ArrowLeftOutlined />}
            hidden={true}
            onClick={() => {
              history.push('/project/masterPlan');
            }}
            type="primary"
          >
            返回
          </Button>,
          <Button
            key="button"
            icon={<RiseOutlined />}
            disabled={releaseBtnFlag || thenumber == 0}
            onClick={() => {
              setreleaseBtnFlag(true);
              releaseProduct();
            }}
            type="primary"
          >
            发布
          </Button>,
          <ModalForm
            //visible={hiddenTemp}
            key="add"
            title="添加批次"
            width={1500}
            modalProps={{
              destroyOnClose: true,
              onCancel: () => {
                setSelections([]);
                actionRef.current?.clearSelected();
              },
              footer: null,
            }}
            trigger={
              <Button
                disabled={hiddenTemp || batchCount === 0}
                type="primary"
                onClick={async () => {
                  await getPlanInfo();
                  //actionRef.current.reload();
                }}
              >
                <PlusOutlined />
                新建
              </Button>
            }
            form={formRef}
            initialValues={{
              batchDeliveryDate: beginFormInfo.batchDeliveryDate,
              batchCount: beginFormInfo.batchCount,
              currentBatch: beginFormInfo.currentBatch + '/' + beginFormInfo.batchCount,
            }}
            onFinish={async (values: any) => {
              const temp = {
                ...formRef.getFieldsValue(),
                currentBatch: formRef.getFieldsValue().currentBatch.split('/')[0],
                masterPlanId: beginFormInfo.masterPlanId,
                infoDeliveryDate: beginFormInfo.infoDeliveryDate,
                selectedBatchProductId: selections,
                // batchDeliveryDate: beginFormInfo.masterPlanDeliveryDate,
              };
              temp.batchDeliveryDate = dayjs(temp.batchDeliveryDate).format('YYYY-MM-DD');
              const result = await addBatchPlan(temp);
              if (result != null) {
                message.success('添加成功');
              }
              actionRef.current?.clearSelected();
              setSelections([]);
              actionRef.current!.reload();
              return true;
            }}
          >
            <ProForm.Group>
              <ProFormDatePicker
                rules={[{ required: true, message: '请输入批次交付日期！' }]}
                name="batchDeliveryDate"
                label="批次交付日期"
              />
              <ProFormText
                width="md"
                name="currentBatch"
                label="当前批次"
                placeholder="请输入名称"
                disabled
              />
            </ProForm.Group>
            <ProForm.Group>
              <Table
                rowKey={(record) => record.batchProductId}
                rowSelection={{
                  ...rowSelection,
                  selectedRowKeys: selections,
                }}
                columns={col}
                scroll={{ x: 650, y: 300 }}
                pagination={{ pageSize: 1000 }}
                dataSource={tableInfo}
              />
            </ProForm.Group>
            <ProFormTextArea
              name="memo"
              label="描述"
              placeholder="请输入描述"
              //fieldProps={inputTextAreaProps}
              width={1450}
            />
          </ModalForm>,
        ]}
        request={async (params = {}, sort, filter) => {
          let infoId;
          if (batchPlanFlag !== undefined && !batchPlanFlag) {
            infoId = batchPlanInfoId;
          } else if (history.location.state && history.location.state.infoId) {
            infoId = history.location.state?.infoId;
          } else {
          }
          const sorters = sortTran(sort);
          const filters = filterTranNew(params);
          let result;
          let allTableData;
          if (infoId) {
            setInfoId(infoId);
            result = await getBatchPlanAndStageByPageAndInfoId({
              infoId,
              pageEntity: {
                ...params,
                sorters: sorters,
                filters: filters,
              },
            });
            allTableData = await getBatchPlanAndStageByPageAndInfoId({
              infoId,
              pageEntity: {
                current: 1,
                pageSize: 100000, //获得全部的数据
                sorters: sorters,
                filters: filters,
              },
            });
            setTableData(allTableData.data.content);
            //获取数量
            const resultCount = await countUnAssginProduct(infoId);
            if (resultCount && (result.data || result.data === 0)) {
              setBatchCount(resultCount.data);
            } else {
              setBatchCount(0);
            }
          } else {
            result = await getBatchPlanAndStageByPage({
              current: 1,
              pageSize: 100000, //获得全部的数据
              sorters: sorters,
              filters: filters,
            });
            allTableData = await getBatchPlanAndStageByPage({
              current: 1,
              pageSize: 100000, //获得全部的数据
              sorters: sorters,
              filters: filters,
            });
            setTableData(allTableData.data.content);
          }
          //数据改造
          setResultLength(result.data.totalElements);
          // console.log(result, 'res');
          const allTemp: any[] = [];
          let count = 0; //由于目前数据库里面有部分内容为null，所以需要统计一下数量，这只是暂时的措施
          result.data.content.map((ele: any) => {
            let temp: any[] = [];
            if (ele === null) {
              count = count + 1;
            }
            if (ele != null) {
              ele.planStagesEx.map((item: any) => {
                temp[`id${item.stageSort}`] = item.id;
                temp[`stageName${item.stageSort}`] = item.stageName;
                temp[`stageStartTime${item.stageSort}`] = item.stageStartTime;
                temp[`stageEndTime${item.stageSort}`] = item.stageEndTime;
                temp[`stagePlanStartTime${item.stageSort}`] = item.stagePlanStartTime;
                temp[`stagePlanEndTime${item.stageSort}`] = item.stagePlanEndTime;
              });
              temp['projectName'] = ele.batchPlanEx.projectName;
              temp['realWorkHour'] = ele.batchPlanEx.realWorkHour;
              temp['workHour'] = ele.batchPlanEx.workHour;
              temp['batchDeliveryDate'] = ele.batchPlanEx.batchDeliveryDate;
              temp['infoId'] = ele.batchPlanEx.infoId;
              temp['id'] = ele.batchPlanEx.id;
              temp['batchDeliveryDate'] = ele.batchPlanEx.batchDeliveryDate;
              temp['infoDeliveryDate'] = ele.batchPlanEx.infoDeliveryDate;
              temp['isReleased'] = ele.batchPlanEx.isReleased;
              temp['currentBatch'] = ele.batchPlanEx.currentBatch;
              // temp['batchCount'] = ele.batchPlanx.batchCount;
              temp['boxCount'] = ele.batchPlanEx.boxCount;
              temp['cabinetCount'] = ele.batchPlanEx.cabinetCount;
              temp['operationCount'] = ele.batchPlanEx.operationCount;
              temp['projectCode'] = ele.batchPlanEx.projectCode;
              temp['othersCount'] = ele.batchPlanEx.othersCount;
              temp['state'] = ele.batchPlanEx.state;
              temp['planReceiptStartDate'] = ele.batchPlanEx.planReceiptStartDate;
              temp['batchCount'] = ele.batchPlanEx.batchCount;
              temp['batchPlanCode'] = ele.batchPlanEx.batchPlanCode;
              temp['reserved'] = ele.batchPlanEx.reserved;
              temp['memo'] = ele.batchPlanEx.memo;
              temp['serialNo'] = ele.batchPlanEx.serialNo;
              temp['masterPlanId'] = ele.batchPlanEx.masterPlanId;
              temp['createTime'] = ele.batchPlanEx.createTime;
              temp['createName'] = ele.batchPlanEx.createName;
              allTemp.push(temp);
            }
          });
          setTempDate(allTemp);
          return {
            data: allTemp,
            total: allTemp.length, //暂时的措施，之后改回result.data.content的数量
            success: result.success,
          };
        }}
        columns={columns}
        scroll={{ x: 2000, y: 600 }}
        pagination={{
          defaultPageSize: 100,
          defaultCurrent: 1,
          pageSizeOptions: [100, 500, 1000],
          showSizeChanger: true,
        }}
        rowSelection={{
          selectedRowKeys: selectedRowKey,
          onSelect: onSelectItem,
          onSelectAll: onSelectedAllItem,
          onSelectNone: () => {
            setSelectedRowKey([]);
          },
        }}
      />
      {/* 添加模块 */}
    </PageHeaderWrapper>
  );
});
export default BatchPlan;
